(function () {
    angular.module('app')
        .component('xxShowQuestionById', {
            templateUrl: '/app/consultant/showQuestionById/showQuestionById.html',
            controller: ctrl
        });

    function ctrl($scope,$stateParams,userService,ShowQuestionByIdFactory,urlCnst) {
        /**
         * purpose:http post
         */
        $scope.essay = [];
        $scope.answer = {
            'body':'',
        };
        $scope.isConsultant = userService.isConsultant;
        var essayId = $stateParams.essayId;
        function getEssayById(essayId) {
            function cb(err,res) {
                if(!err)$scope.essay = res;
            }
            ShowQuestionByIdFactory.getEssayById(essayId,cb);
        }
        getEssayById(essayId);
        //console.log($scope.essay);

        $scope.postAnswer =function (body) {
            //TODO set consultantId
            body.consultantId = userService['consultantId'];
            //console.log(body);
            if(!body||!body['body']){
                urlCnst.notice("请输入回答后再提交");
                return;
            }
            function cb(err,res) {
                urlCnst.notice("感谢回答")
            }
            ShowQuestionByIdFactory.postAnswer(essayId,body,cb);
        };
    }


})()
